package com.lagou.edu.utils;

import com.lagou.edu.annotation.MyAutowired;
import com.lagou.edu.annotation.MyService;

import java.sql.SQLException;

@MyService
public class TransactionManager {
    @MyAutowired
    private TransactionManager(){
    }

    private static TransactionManager transactionManager = new TransactionManager();

    public static TransactionManager getInstance() {
        return transactionManager;
    }

    public void startTransacion() throws SQLException {
        ConnectionUtils.getInstance().getCurrentThreadCoon().setAutoCommit(false);
    }

    public void commit() throws SQLException {
        ConnectionUtils.getInstance().getCurrentThreadCoon().commit();
    }

    public void rollback() throws SQLException {
        ConnectionUtils.getInstance().getCurrentThreadCoon().rollback();
    }
}
